package com.masterclient.app.modules.aftersale;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.View;
import android.widget.RelativeLayout;

import com.alibaba.android.arouter.launcher.ARouter;
import com.eoner.managerlibrary.router.AroutePath;
import com.masterclient.app.BaseActivity;
import com.masterclient.app.R;
import com.masterclient.app.widget.TitlebarView;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 作者：sean
 * 创建时间：2017/7/27 19:48
 * 功能说明：
 */

public class ChooseAfterSaleActivity extends BaseActivity {

    @BindView(R.id.rl_tuikuan)
    RelativeLayout rlTuikuan;
    @BindView(R.id.rl_tuihuo)
    RelativeLayout rlTuihuo;
    @BindView(R.id.title_view)
    TitlebarView titleView;
    @BindView(R.id.rl_bufa)
    RelativeLayout rlBufa;

    String product_id,order_id,fromType;
    private String state,update;
    private List<Integer> show_list;

    public final static int RESULT_SUCCESS = 1001;

    public static ChooseAfterSaleActivity instance;
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        instance = this;
        setContentView(R.layout.activity_choose_after_sale);
        ButterKnife.bind(this);

        titleView.setOnViewClick(new TitlebarView.onViewClick() {
            @Override
            public void leftClick() {
                finish();
            }

            @Override
            public void rightClick() {

            }
        });

        show_list = getIntent().getIntegerArrayListExtra("show_list");
        product_id = getBundleString("product_id");
        order_id = getBundleString("order_id");
        fromType = getBundleString("from_type");
        state = getBundleString("state");
        update = getBundleString("update");
        for (int showType : show_list) {
            switch (showType){
                case 0:
                    rlTuikuan.setVisibility(View.VISIBLE);
                    break;
                case 1:
                    rlTuihuo.setVisibility(View.VISIBLE);
                    break;
                case 2:
                    rlBufa.setVisibility(View.VISIBLE);
                    break;
            }
        }
    }

    @OnClick({R.id.rl_bufa,R.id.rl_tuikuan,R.id.rl_tuihuo}) void onClick(View view){
        switch (view.getId()){
            case R.id.rl_tuikuan:
                startActivitryForResult(ReturnMoneyActivity.class,new String[][]{{"product_id",product_id},{"from_type",fromType},{"order_id",order_id},{"update",update}});
//                startActivitry(ReturnMoneyActivity.class,new String[][]{{"product_id",product_id},{"update",update}});
                break;
            case R.id.rl_tuihuo:
                startActivitryForResult(ReturnGoodsActivity.class,new String[][]{{"product_id",product_id},{"from_type",fromType},{"order_id",order_id},{"update",update}});
//                startActivitry(ReturnGoodsActivity.class,new String[][]{{"product_id",product_id},{"update",update}});
                break;
            case R.id.rl_bufa:
                ARouter.getInstance().build(AroutePath.RETURN_REDELIVER_ACTIVITY).withString("product_id", product_id).withString("from_type",fromType)
                        .withString("update", update).withString("order_id", order_id).navigation(this,100);
                break;
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        switch (resultCode){
            case RESULT_SUCCESS:
                setResult(RESULT_SUCCESS);
                finish();
                break;
        }
    }
}
